﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DimOS.Cat
{
    /// <summary>
    /// Used in the executor to implement the main stack and auxiliary stack.
    /// </summary>
    public class Stack : BaseCatStack<object>
    {
    }

    /// <summary>
    /// More of a Dequeue than a Stack data type, but it doesn't hurt anyone.
    /// This class might get significantly overhauled in the future. 
    /// </summary>
    public class BaseCatStack<T> : List<T>
    {
        private List<T> GetBase()
        {
            return this;
        }
        public T Peek()
        {
            return this[0];
        }
        public new T this[int index]
        {
            get
            {
                return GetBase()[(Count - 1) - index];
            }
            set
            {
                GetBase()[(Count - 1) - index] = value;
            }
        }
        public T Push(T x)
        {
            Add(x);
            return Peek();
        }
        public T PushFront(T x)
        {
            Insert(0, x);
            return x;
        }
        public T Pop()
        {
            T x = Peek();
            RemoveAt(Count - 1);
            return x;
        }
        public T PopFront()
        {
            T x = this[0];
            RemoveAt(0);
            return x;
        }
        public bool IsEmpty()
        {
            return Count == 0;
        }
    }
}
